// EG4RunAction.cxx -- implementation of the class
// Created: Jan. 27, 2019, transcribed by Asia SUN, asia.rabbit@163.com
// Last modified: Jan. 27, 2019, by Asia SUN

#include <unistd.h>
#include "G4RunManager.hh"
#include "CLHEP/Random/RandomEngine.h" // from clhep
#include "EG4RunAction.h"
#include "EG4ROOT.h"

EG4RunAction::EG4RunAction(EG4ROOT *r) : G4UserRunAction(){
  if(!r){
    std::cerr << "nullptr EG4ROOT encountered" << std::endl;
    exit(1);
  } // end if
  fROOT = r;
} // end ctor

EG4RunAction::~EG4RunAction(){}

void EG4RunAction::BeginOfRunAction(const G4Run */*run*/){
  // randomize the random engine
  CLHEP::HepRandom::setTheSeed(rand(), 4);
} // end member function BeginOfRunAction

void EG4RunAction::EndOfRunAction(const G4Run *){}

void EG4RunAction::Fill(){
  fROOT->Fill();
} // end member function Fill

EG4Data *EG4RunAction::data() const{
  return fROOT->data();
} // end member function data
